Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes thread safety issues in the singleton implementation of NostrSpringWebSocketClient by implementing proper double-checked locking and ensuring the singleton instance is properly assigned when created. It also adds comprehensive unit tests to verify the singleton behavior works correctly.
- Implements thread-safe singleton pattern using volatile field and synchronized double-checked locking
- Ensures created instances are properly assigned to the static INSTANCE field
- Adds unit tests with reflection-based singleton reset for proper isolation
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| NostrSpringWebSocketClient.java | Implements thread-safe singleton pattern with volatile field and double-checked locking |
| NostrSpringWebSocketClientTest.java | Adds unit tests for singleton behavior with proper test isolation using reflection |
Comments suppressed due to low confidence (1)
nostr-java-api/src/test/java/nostr/api/unit/NostrSpringWebSocketClientTest.java:34
- The test doesn't verify that the Identity from the first call is actually preserved in the singleton instance. It only checks reference equality but not the functional behavior of the Identity parameter.
assertSame(first, second, "Calls with and without identity should return the same instance");
…ent.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NostrSpringWebSocketClientINSTANCETesting
mvn -q verify -DskipITs(fails: log truncated before completion)mvn verify -DskipTestshttps://chatgpt.com/codex/tasks/task_b_688a865c72c48331b30e7e458d6ba167